﻿CREATE PROCEDURE [dbo].[Hogar_Integrante_AsistenAActividad]
 @ActividadId INT
AS
BEGIN
	-- Integrantes que asisten a la actividad
	SELECT i.[IntegranteId],
		   [Apellido] + ' ' + [Nombre] AS [NombreCompleto],
		   [Dni],
		   CASE WHEN [ObraSocialId] = 1 THEN 1 ELSE 0 END AS [TienePami],
		   '' AS [Dias]
	FROM [dbo].[Integrante] i WITH (NOLOCK)
	INNER JOIN [dbo].[Inscripcion] ins WITH (NOLOCK) ON i.[IntegranteId] = ins.[IntegranteId] 
				AND ins.[ActividadId] = @ActividadId AND ins.[Activa] = 1
	ORDER BY [Apellido], [Nombre]

	-- Dias que asisten los integrantes a la actividad
	SELECT ac.[IntegranteId],
		   ac.[ActividadId],
		   [DiaSemanaId]
	FROM [dbo].[AsisteComedorViandaDias] ac WITH (NOLOCK)
	INNER JOIN [dbo].[Inscripcion] ins WITH (NOLOCK) ON ac.[IntegranteId] = ins.[IntegranteId] 
				AND ac.[ActividadId] = ins.[ActividadId] AND ins.[Activa] = 1
	WHERE ac.[ActividadId] = @ActividadId
END
